package com.example.base.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.base.R;


/**
 * Author by zhengbenying
 * Email zhengbenying@hikvison.com
 * Company 杭州海康威视数字技术股份有限公司
 * Date on 2018/9/20
 */
public class StatusViewHelper2 {
    private Context mContext;
    private FrameLayout mContentLayout;
    private View tipsView ;
    private View loadingView ;
    private View targetView ;
    private LayoutInflater mInflater;
    public StatusViewHelper2(Context mContext, int layoutResID) {
        this.mContext = mContext;
        initView(layoutResID);
    }

    private void initView(int layoutResID){
        FrameLayout.LayoutParams layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.mInflater = LayoutInflater.from(mContext);
        if (layoutResID != 0) {
            targetView = mInflater.inflate(layoutResID, null);
            targetView.setLayoutParams(layoutParam);
        }
        //页面正文部分
        mContentLayout = new FrameLayout(mContext);

        //设置一个异常显示的界面视图
        tipsView = mInflater.inflate(R.layout.ny_safeproduction_base_tips, null);
        tipsView.setLayoutParams(layoutParam);
        loadingView = mInflater.inflate(R.layout.base_lib_base_loading,null);
        loadingView.setLayoutParams(layoutParam);
        mContentLayout.addView(targetView);
        mContentLayout.addView(tipsView);
        mContentLayout.addView(loadingView);
        tipsView.setVisibility(View.GONE);
        loadingView.setVisibility(View.GONE);
    }

    public FrameLayout getContentLayout() {
        return mContentLayout;
    }
    public void showTargetView(){
        targetView.setVisibility(View.VISIBLE);
        tipsView.setVisibility(View.GONE);
        loadingView.setVisibility(View.GONE);
    }
    //显示提示内容
    public void showTipsView(String content, int...resId){
        targetView.setVisibility(View.GONE);
        tipsView.setVisibility(View.VISIBLE);
        loadingView.setVisibility(View.GONE);
        if(resId.length>0&&resId[0]!=0){
            ((ImageView)tipsView.findViewById(R.id.ny_safeproduction_base_tips_iv)).setImageResource(resId[0]);
        }
        ((TextView)tipsView.findViewById(R.id.ny_safeproduction_base_tips_tv)).setText(content);
    }

    public void showLoadingView(){
        targetView.setVisibility(View.GONE);
        tipsView.setVisibility(View.GONE);
        loadingView.setVisibility(View.VISIBLE);
    }

    /**
     * 点击提示图片重新加载
     * @param iStatusReloadCallback
     */
    public void reLoad(final IStatusReloadCallback2 iStatusReloadCallback){
        tipsView.findViewById(R.id.ny_safeproduction_base_tips_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iStatusReloadCallback.click();
            }
        });
    }


}
